const path = require('path');
const MonacoEditorPlugin = require('monaco-editor-webpack-plugin')

const resolve = dir => {
  return path.join(__dirname, dir)
}

module.exports = {
  assetsDir: 'static',
  publicPath: '/',
  configureWebpack: {
    node: {
      process: true,
    },
    plugins: [
      new MonacoEditorPlugin({
        features: ['!gotoSymbol'],
        // https://github.com/Microsoft/monaco-editor-webpack-plugin#options
        // Include a subset of languages support
        // Some language extensions like typescript are so huge that may impact build performance
        // e.g. Build full languages support with webpack 4.0 takes over 80 seconds
        // Languages are loaded on demand at runtime
        languages: ['yaml']
      })
    ]
  },
  chainWebpack: config => {
    config.resolve.alias
      .set('@node_modules', resolve('node_modules'))
      .set('@', resolve('src')) // key,value自行定义，比如.set('@@', resolve('src/components'))
      .set('@components', resolve('src/components'))
      .set('@views', resolve('src/views'))
    config.optimization.minimize(true)
    config.optimization.splitChunks({
      chunks: 'all'
    })
    config.externals({
      vue: 'Vue',
      vuex: 'Vuex',
      iview: 'iview',
      'vue-router': 'VueRouter'
    })
    config.module
      .rule('shell')
      .test(/\.(sh|bat|cmd)(\?.*)?$/)
      .use('file')
      .loader('file-loader')
      .options({
        name: '[name].[ext]',
        outputPath: 'public/'
      })
  },
  css: {
    extract: true,
    loaderOptions: {
      // 给 sass-loader 传递选项
      less: {
        javascriptEnabled: true
      }
    }
  },
  productionSourceMap: false,
  lintOnSave: false
};
